﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

using Aliphant.Mvvm.XEvent.Events;
using Aliphant.UI;
using Aliphant.UI.Widgets;
using Aliphant.UI.Windows;

using TestModule.Models;

namespace TestModule.Widgets
{
    /// <summary>
    /// WidgetStock.xaml 的交互逻辑
    /// </summary>
    public partial class WidgetStock : BaseWidget, IWidget
    {
        private WindowEvent _windowEvent;
        private bool _thumbStatus;
        private bool _opacityStatus;

        public WidgetStock()
        {
            InitializeComponent();
            _windowEvent = Test.EventAgent.GetEvent<WindowEvent>();
        }

        public void Init(Widget widget)
        {

        }

        public string? QuickButton1Tip => "折叠/展开";

        public string? QuickButton2Tip => "显示/隐藏";

        public string? QucikButton1Icon => "Icon.TriangleDown";

        public string? QucikButton2Icon => "Icon.Show";

        public void SetScriptPath(string scriptPath)
        {

        }

        public void QuickAction1()
        {
            SwitchThumb();
        }

        public void QuickAction2()
        {
            SwitchOpacity();
        }

        public void Close()
        {
            _windowEvent.Publish(new WindowEvent
            {
                Type = EventType.Action,
                WindowActionType = WindowActionType.Close,
                EventId = EventIds.Release
            });
        }


        public void SwitchThumb()
        {
            if (_thumbStatus)
            {
                _thumbStatus = false;
                thumb.Visibility = Visibility.Collapsed;
                complete.Visibility = Visibility.Visible;
            }
            else
            {
                _thumbStatus = true;
                thumb.Visibility = Visibility.Visible;
                complete.Visibility = Visibility.Collapsed;
            }
        }

        public void SwitchOpacity()
        {
            if (_opacityStatus)
            {
                _opacityStatus = false;
                mainBg.Background = new SolidColorBrush(Color.FromArgb(204, 96, 94, 92));
                this.Opacity = 1;
            }
            else
            {
                _opacityStatus = true;
                mainBg.Background = new SolidColorBrush(Color.FromArgb(0, 96, 94, 92));
                this.Opacity = 0.4;
            }
        }

    }
}
